
#include "stdafx.h"
#include "displayfrm.h"
#include "displayhelper.h"
#include "apphandler\snbfileprotocol.h"

CDisplayFrame::CDisplayFrame() 
: CFrameSkinMixIn<CDisplayFrame>(new CMainFrmAspect)
{
}

void CDisplayFrame::OnFinalMessage(HWND hWnd)
{
	delete this;
}

LRESULT CDisplayFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CenterWindow();
	SetWindowText(_T("Book"));

	m_TabCtrl.Create(m_hWnd);
	m_MdiClient.CreateClient(m_hWnd, &m_TabCtrl);

	m_Mediator.Register(this);
	m_Mediator.Register(&m_TabCtrl);
	m_Mediator.Register(&m_MdiClient);

	return 0;
}

LRESULT CDisplayFrame::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	DestroyWindow();
	return 0;
}

LRESULT CDisplayFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	return 0;
}

LRESULT CDisplayFrame::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	CWindowRect rect(m_hWnd);
	CRect rcCtrl;

	int iCaptionHeight = 32;
	int iTabHeight = 30;

	CDeferWindowPos dwp;

	rcCtrl.SetRect(1, iCaptionHeight, rect.Width() - 1, iCaptionHeight + iTabHeight);
	dwp.DeferWindowPos(m_TabCtrl, rcCtrl, SWP_NOZORDER);

	rcCtrl.SetRect(1, iCaptionHeight + iTabHeight, rect.Width() - 2, rect.Height() - 2);
	dwp.DeferWindowPos(m_MdiClient, rcCtrl, SWP_NOZORDER);

	return 0;
}

LRESULT CDisplayFrame::OnGetMinMaxInfo(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
	LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
	lpMMI->ptMinTrackSize.x = 160;
	lpMMI->ptMinTrackSize.y = 120;

	return 0;
}

bool CDisplayFrame::Navigate(LPCTSTR lpszUrl)
{
	//SetWindowText(strTitle);
	m_MdiClient.CreateFrame(lpszUrl);

	return true;
}

LRESULT CDisplayFrame::OnCopyData(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
	PCOPYDATASTRUCT pcps = (PCOPYDATASTRUCT)lParam;
	if (pcps->dwData == (ULONG)m_hWnd)
	{
		class CreatePageData* pData  = (class CreatePageData*)pcps->lpData;
		LPCTSTR lpszUrl = (LPCTSTR)((LPBYTE)pData + sizeof(DWORD));
		return (LRESULT)m_MdiClient.CreateFrame(_T(""));
	}

	return NULL;
}